package com.xunua.MyFecDemo;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.util.Log;
import android.widget.TextView;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {
    private static final String TAG="MainActivity";
    public String mName="Test";
    public int num=0;

    // Used to load the 'native-lib' library on application startup.
    static {
        System.loadLibrary("native-lib");
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        // Example of a call to a native method
        TextView tv = findViewById(R.id.sample_text);
        tv.setText(stringFromJNI());
        CallbackExample myCallback = new CallbackExample(new MyCallback() {
            @Override
            public void onCallback(String message) {
                Log.e(TAG, "onCallback---- 返回了信息："+message);
            }
        });
        myCallback.callNativeMethod();

        for (int i = 0; i < 10; i++) {
            putDecodeString("传入数据："+i,100);
        }

        Log.e(TAG, "onCreate: "+mName+"  num:"+num);
        func3();
        Log.e(TAG, "onCreate: "+mName+"  num:"+num);
        tv.setText(mName+"  "+num);

        func4();

        Toast.makeText(this, ""+intFromJNI(), Toast.LENGTH_SHORT).show();
    }

    /**
     * A native method that is implemented by the 'native-lib' native library,
     * which is packaged with this application.
     */
    public native String stringFromJNI();

    public native void putDecodeString(String message,int requestCode);

    public native void func3();

    public native void func4();
    public native int intFromJNI();

    /**
     * 创建普通函数，用于native来调用当前函数。实现回调。
     * @param code
     */
    public void onCallback(int code){
        Toast.makeText(this, "被native回调了，code："+code, Toast.LENGTH_SHORT).show();
    }
}